﻿using System;
using System.ComponentModel;
using System.Windows;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for Machine.xaml
    /// </summary>

    public partial class TCOMYBJ
    {
        #region ==DevTyp===========
        public static readonly DependencyProperty DevTypProperty = DependencyProperty.Register("DevTyp",
            typeof(string), typeof(TCOMYBJ),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDevTypChanged));
        public string DevTyp
        {
            get
            {
                return (string)GetValue(DevTypProperty);
            }
            set
            {
                SetValue(DevTypProperty, value);
            }
        }
        private static void OnDevTypChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TCOMYBJ;
            if (src != null)
            {
                src.DevTyp = (string)e.NewValue;
            }
        }
        public virtual void OnDevTypChg(string value)
        { }
        #endregion
       
        #region ==COMn===========
        public static readonly DependencyProperty COMnProperty = DependencyProperty.Register("COMn",
            typeof(string), typeof(TCOMYBJ),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCOMnChanged));
        public string COMn
        {
            get
            {
                return (string)GetValue(COMnProperty);
            }
            set
            {
                SetValue(COMnProperty, value);
            }
        }
        private static void OnCOMnChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TCOMYBJ;
            if (src != null)
            {
                src.COMn = (string)e.NewValue;
            }
        }
        #endregion 

        #region ==CBaudRate===========
        public static readonly DependencyProperty CBaudRateProperty = DependencyProperty.Register("CBaudRate",
                typeof(int), typeof(TCOMYBJ),
                new FrameworkPropertyMetadata(9600, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCBaudRateChanged));
        public int CBaudRate
        {
            get
            {
                return (int)GetValue(CBaudRateProperty);
            }
            set
            {
                SetValue(CBaudRateProperty, value);
            }
        }
        private static void OnCBaudRateChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TCOMYBJ;
            if (src != null)
            {
                src.CBaudRate = (int)e.NewValue;
            }
        }
        #endregion
      
        #region ==CStopBits===========
        public static readonly DependencyProperty CStopBitsProperty = DependencyProperty.Register("CStopBits",
                typeof(int), typeof(TCOMYBJ),
                new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCStopBitsChanged));
        public int CStopBits
        {
            get
            {
                return (int)GetValue(CStopBitsProperty);
            }
            set
            {
                SetValue(CStopBitsProperty, value);
            }
        }
        private static void OnCStopBitsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TCOMYBJ;
            if (src != null)
            {
                src.CStopBits = (int)e.NewValue;
            }
        }
        #endregion


        #region ==CDataBits===========
        public static readonly DependencyProperty CDataBitsProperty = DependencyProperty.Register("CDataBits",
                typeof(int), typeof(TCOMYBJ),
                new FrameworkPropertyMetadata(9600, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCDataBitsChanged));
        public int CDataBits
        {
            get
            {
                return (int)GetValue(CDataBitsProperty);
            }
            set
            {
                SetValue(CDataBitsProperty, value);

            }
        }
        private static void OnCDataBitsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TCOMYBJ;
            if (src != null)
            {
                src.CDataBits = (int)e.NewValue;
            }
        }
        #endregion

        #region ==CParity
       
        public static readonly DependencyProperty CParityProperty = DependencyProperty.Register("CParity",
                typeof(int), typeof(TCOMYBJ),
                new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCParityChanged));
        public int CParity
        {
            get
            {
                return (int)GetValue(CParityProperty);
            }
            set
            {
                SetValue(CParityProperty, value);

            }
        }
        private static void OnCParityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TCOMYBJ;
            if (src != null)
            {
                src.CParity = (int)e.NewValue;
            }
        }
        #endregion
        public TCOMYBJ()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAMSTAMM();
            DataContext = MV;
            InitializeComponent(); 
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return; 
            base.Window_Loaded(sender, e);
            
        }
      
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
             
        }
       
        public override void OnVU0Chg(string value)
        {
            QTY = double.Parse(VU0) * 1000;
            base.OnVU0Chg(value);
        }
    }
}
